﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Transaction.Interceptor;
using OpenSda.Agilcont.Common.Data.Entities;
using OpenSda.Agilcont.Common.Data.Contracts;
using OpenSda.Agilcont.Common.Business.Exceptions;
using OpenSda.Agilcont.Common.Business.Contracts;

namespace OpenSda.Agilcont.Common.Business.SfContexts
{
    public class DataAccessAgenciaConfigBusiness : IDataAccessAgenciaConfigBusiness
    {
        IDataAccessAgenciaConfigData dataAccessAgenciaConfigData;
        IModuleAccessData moduleAccessData ;
        public IDataAccessAgenciaConfigData DataAccessAgenciaConfigData { set { dataAccessAgenciaConfigData = value; } }
        public IModuleAccessData ModuleAccessData { set { moduleAccessData = value; } }

        public DataAccessAgenciaConfigBusiness()
        {
            
        }

        [Transaction]
        public DataAccessAgenciaConfig Save(DataAccessAgenciaConfig dataAccessAgenciaConfig)
        {
            if (dataAccessAgenciaConfig == null)
                throw new DataAccessAgenciaConfigCannotBeNullException();
            // Não permitir duplicar Codigo
            if (dataAccessAgenciaConfigData.GetAllQueryable().Where(ms => ms.Identity != dataAccessAgenciaConfig.Identity && ms.Role == dataAccessAgenciaConfig.Role).Count() > 0)
                throw new DataAccessAgenciaConfigRoleInUseException();

            //// Não permitir duplicar RazonSocial
            //if (empresaData.GetAllQueryable().Where(ms => ms.Identity != empresa.Identity && ms.RazonSocial == empresa.RazonSocial).Count() > 0)
            //    throw new EmpresaNameInUseException();

            return dataAccessAgenciaConfigData.Save(dataAccessAgenciaConfig);
        }

        //public DataAccessAgenciaConfig Delete(DataAccessAgenciaConfig dataAccessAgenciaConfig)
        //{
        //    throw new NotImplementedException();
        //}

        public DataAccessAgenciaConfig GetById(Guid guid)
        {
           // DataAccessAgenciaConfig.Identity=Guid.Empty
            
            return dataAccessAgenciaConfigData.Select(guid);
        }

        //public DataAccessAgenciaConfig GetListByFilter(string filter)
        //{
        //    throw new NotImplementedException();
        //}
    }
}
